package com.jsz.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.jsz.dao.MemberDao;
import com.jsz.pojo.Member;
import com.jsz.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceimpl implements MemberService {

    @Autowired
    private MemberDao memberDao;

    //根据手机号查询会员信息
    @Override
    public Member findByTelephone(String telephone) {
        return memberDao.findByTelephone(telephone);
    }

    //添加用户信息
    @Override
    public void add(Member member) {
        memberDao.add(member);
    }

    //根据月份查询会员统计信息
    @Override
    public List<Integer> findMemberCountByMonth(List<String> months) {
        //创建一个list集合用来存储数据
        List<Integer> memberCount = new ArrayList<>();
        for (String month : months) {
            //获取到每一个月份信息
            String date = month + "31";
            //代用dao层,根据月份信息查询数据
            Integer count = memberDao.findMemberCountBeforeDate(date);
            //讲查询到的数据封装到list集合中
            memberCount.add(count);
        }
        return memberCount;
    }

    //根据订单ID查询会员信息
    @Override
    public Member findByOrderId(Integer id) {
        return memberDao.findByOrderId(id);
    }
}
